// 校验学号
export const checkUsername = (rule: any, value: any, callback: any) => {
  if (value === '') {
    callback(new Error('请输入学号'))
  } else if (value.length != 12) {
    callback(new Error('请输入正确的学号'))
  } else {
    callback()
  }
}

// 校验密码
export const checkPassword = (rule: any, value: any, callback: any) => {
  if (value === '' || value === null) {
    callback(new Error('请输入密码'))
  } else if (value.length < 6) {
    callback(new Error('密码必须大于6位'))
  } else {
    callback()
  }
}

// 校验验证码
export const checkCode = (rule: any, value: any, callback: any) => {
  if (value === '' || value === null) {
    callback(new Error('请输入验证码'))
  } else if (value.length != 6) {
    callback(new Error('验证码有误'))
  } else {
    callback()
  }
}

// 校验邮箱
export const checkEmail = (rule: any, value: any, callback: any) => {
  const mailReg =
    /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})(;([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4}))*$/
  if (!value) {
    return callback(new Error('邮箱不能为空'))
  }
  setTimeout(() => {
    if (mailReg.test(value)) {
      callback()
    } else {
      callback(new Error('请输入正确的邮箱格式'))
    }
  }, 100)
}

export const checkPhone = (rule: any, value: any, callback: any) => {
  if (value === '' || value === null) {
    callback(new Error('请输入手机号'))
  } else if (value.length != 11) {
    callback(new Error('请输入正确的手机号'))
  }
  callback()
}
// 非空校验
export const checkCommon = (rule: any, value: any, callback: any) => {
  if (value === '' || value === null) {
    callback(new Error('该信息不能为空'))
  } else {
    callback()
  }
}
